/**
 * 全局配置
 * @type {{uploadConfig: {headers: (function(): {}), uploadURL: string, enable: boolean, previewHandle: (function(*): string), onUploadSuccess: (function(*, *, *): {name: *, url: *})}}}
 */
let globalConfig = {
    uploadConfig: { // 上传文件配置
        enable: false, // 是否启用全局上传文件配置
        uploadURL: "http://127.0.0.1/upload", // 上传文件URL地址
        previewHandle: (filePath) => { // 预览文件时，对文件路径进行处理
            return "http://127.0.0.1/preview?filePath=" + filePath
        },
        headers: () => { // 设置上传的请求头部
            return {}
        },
        onUploadSuccess: (res, file, fileList) => { // 对上传后的返回结果进行处理
            return { // 必需返回以下两个属性
                name: res.fileName,
                url: res.url
            }
        }
    },
}
/**
 * 设置全局配置
 * @param config
 */
export const setGlobalConfig = (config) => {
    globalConfig = Object.assign({}, globalConfig, !!config ? config : {})
}

/**
 * 获取全局配置
 * @returns {{axios: null, uploadConfig: {uploadURL: string, enable: boolean, previewHandle: (function(*): string), onUploadSuccess: (function(*, *, *): {name: *, url: *})}}}
 */
export const getGlobalConfig = () => {
    return globalConfig
}